package com.itgaoshu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itgaoshu.bean.Report;
import com.itgaoshu.service.ReportSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("report")
public class ReportController {
    @Autowired
    private ReportSerivce reportSerivce;

    /**
     * 挂号的Controller层
     */
    /*
     *查询挂号单的方法
     */
    @RequestMapping("listreportby")
    @ResponseBody
    public Object listreportby(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Report> reports = reportSerivce.listReporty();
        PageInfo pageInfo = new PageInfo(reports);
        Map<String, Object> drugstoresData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        drugstoresData.put("code", 0);
        drugstoresData.put("msg", "");
        //将全部数据的条数作为count传给前台
        drugstoresData.put("code", pageInfo.getTotal());
        //将分页后的数据返回
        drugstoresData.put("data", pageInfo.getList());
        return drugstoresData;
    }

    ;

    /*
     * 添加挂号单的方法
     * */
    @RequestMapping("addreport")
    @ResponseBody
    public Object addreport(Report report) {
        int i = reportSerivce.addreport(report);
        if (i > 0) {//添加成功
            return "listreportby";
        } else {//添加失败

            return "";
        }

    }

    ;

    @RequestMapping("deletereportbyid")
    @ResponseBody
    public String deletereportbyid(int reportid) {
        int i = reportSerivce.deletereporbyid(reportid);
        if (i > 1) {//删除成功
            return "listreportby";

        } else {
            return "";

        }

    }


    ;

}
